package com.miukoo.aikao.core.exceptions;

import com.miukoo.aikao.core.dtos.ApiResult;
import com.miukoo.aikao.core.enums.ApiError;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.NoArgsConstructor;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ApiException extends RuntimeException {

    /**
     * 错误码
     */
    private Integer code;

    /**
     * 错误消息
     */
    private String msg;

    /**
     * 从结果初始化
     * @param apiResult
     */
    public ApiException(ApiResult apiResult){
        this.code = apiResult.getCode();
        this.msg = apiResult.getMsg();
    }

    /**
     * 从枚举中获取参数
     * @param apiError
     */
    public ApiException(ApiError apiError){
        this.code = apiError.getCode();
        this.msg = apiError.msg;
    }

}
